package com.back_end.Reflection;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException {
        Person person = new Student();
        System.out.println("这个人是:" + person.name);

        // 方式1:通过对象获得
        Class<? extends Person> aClass = person.getClass();
        // 方式2:forname获得
        Class<?> aClass1 = Class.forName("com.back_end.Reflection.Student");

        // 方式3:通过类名.class获得
        Class<Student> studentClass = Student.class;



        System.out.println("c1:" + aClass + ":" + aClass.hashCode());
        System.out.println("c2:" + aClass1 + ":" + aClass1.hashCode());
        System.out.println("c3:" + studentClass + ":" + studentClass.hashCode());



    }

}

class Person{
    public String name;

    public Person() {
    }

    public Person(String name) {
        this.name = name;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

class Student extends Person{
    public Student(){
        this.name = "学生";
    }
}

class Teacher extends Person{
    public Teacher(){
        this.name = "老师";
    }
}
